package com.tengju.bff.infrastructure.export.convert;

import com.tengju.bff.interfaces.manage.crm.dealer.vo.DealerAreaInfoVO;
import com.tengju.bff.interfaces.manage.crm.dealer.vo.DealerCustInfoVO;
import com.tengju.bff.interfaces.manage.crm.dealer.vo.DealerSupInfoVO;
import com.tengju.bff.interfaces.manage.crm.dealer.vo.ExportCrmDealerInfoVO;
import com.tengju.export.domain.record.Table;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/25 9:39 上午
 */
public class ExportCrmDealerInfoVoConvert {

    public static Table convert(List<ExportCrmDealerInfoVO> crmDealerInfoVOList) {
        Table table = new Table();
        table.setHeader(buildHeader());
        table.setRecords(buildRecords(crmDealerInfoVOList));
        return table;
    }

    private static List<List<String>> buildRecords(List<ExportCrmDealerInfoVO> crmDealerInfoVOList) {
        //构造导出数据
        int index = 1;
        List<List<String>> dataList = new ArrayList<>();
        for (ExportCrmDealerInfoVO dealerInfoVO : crmDealerInfoVOList) {
            List<String> row = new ArrayList<>();

            row.add(String.valueOf(index));
            row.add(String.valueOf(dealerInfoVO.getIdCode()));
            row.add(dealerInfoVO.getUserName() == null ? "" : dealerInfoVO.getUserName());
            row.add(dealerInfoVO.getNickName() == null ? "" : dealerInfoVO.getNickName());
            row.add(dealerInfoVO.getLevel() == null ? "" : dealerInfoVO.getLevel());
            row.add(dealerInfoVO.getApplyType() == null ? "" : dealerInfoVO.getApplyType());
            row.add(dealerInfoVO.getStarLevel() == null ? "" : dealerInfoVO.getStarLevel());
            row.add(dealerInfoVO.getUserCountry() == null ? "" : dealerInfoVO.getUserCountry());
            row.add(dealerInfoVO.getUserProvince() == null ? "" : dealerInfoVO.getUserProvince());
            row.add(dealerInfoVO.getUserCity() == null ? "" : dealerInfoVO.getUserCity());

            //上级信息
            DealerSupInfoVO dealerSupInfoVO = dealerInfoVO.getDealerSupInfoVO();
            if (dealerSupInfoVO != null) {
                row.add(dealerSupInfoVO.getSupUserName() == null ? "" : dealerSupInfoVO.getSupUserName());
                row.add(dealerSupInfoVO.getAsscHkName() == null ? "" : dealerSupInfoVO.getAsscHkName());
                row.add(dealerSupInfoVO.getBlStar1Name() == null ? "" : dealerSupInfoVO.getBlStar1Name());
                row.add(dealerSupInfoVO.getBlStar2Name() == null ? "" : dealerSupInfoVO.getBlStar2Name());
                row.add(dealerSupInfoVO.getBlStar3Name() == null ? "" : dealerSupInfoVO.getBlStar3Name());
                row.add(dealerSupInfoVO.getBlStar4Name() == null ? "" : dealerSupInfoVO.getBlStar4Name());
                row.add(dealerSupInfoVO.getBlEcName() == null ? "" : dealerSupInfoVO.getBlEcName());
                row.add(dealerSupInfoVO.getBlSecName() == null ? "" : dealerSupInfoVO.getBlSecName());
                row.add(dealerSupInfoVO.getBlClubName() == null ? "" : dealerSupInfoVO.getBlClubName());
            }

            //大区信息
            DealerAreaInfoVO dealerAreaInfoVO = dealerInfoVO.getDealerAreaInfoVO();
            if (dealerAreaInfoVO != null) {
                row.add(dealerAreaInfoVO.getAreaHkCount());
                row.add(dealerAreaInfoVO.getAreaSVIPCount() == null ? "" : dealerAreaInfoVO.getAreaSVIPCount());
                row.add(dealerAreaInfoVO.getAreaVVIPCount() == null ? "" : dealerAreaInfoVO.getAreaVVIPCount());
                row.add(dealerAreaInfoVO.getAreaVIPCount() == null ? "" : dealerAreaInfoVO.getAreaVIPCount());
                row.add(dealerAreaInfoVO.getAreaRuCount() == null ? "" : dealerAreaInfoVO.getAreaRuCount());
            }

            //直属客户信息
            DealerCustInfoVO dealerCustInfoVO = dealerInfoVO.getDealerCustInfoVO();
            if (dealerCustInfoVO != null) {
                row.add(dealerCustInfoVO.getCustHkCount() == null ? "" : dealerCustInfoVO.getCustHkCount());
                row.add(dealerCustInfoVO.getCustSVIPCount() == null ? "" : dealerCustInfoVO.getCustSVIPCount());
                row.add(dealerCustInfoVO.getCustVVIPCount() == null ? "" : dealerCustInfoVO.getCustVVIPCount());
                row.add(dealerCustInfoVO.getCustVIPCount() == null ? "" : dealerCustInfoVO.getCustVIPCount());
                row.add(dealerCustInfoVO.getCustRuCount() == null ? "" : dealerCustInfoVO.getCustRuCount());
            }

            row.add(dealerInfoVO.getLevelChgAt() == null ? "" : dealerInfoVO.getLevelChgAt());

            dataList.add(row);
            index++;
        }
        return dataList;
    }

    private static List<String> buildHeader() {
        List<String> headerList = new ArrayList<>();
        headerList.add("序号");
        headerList.add("会员id");
        headerList.add("姓名");
        headerList.add("昵称");
        headerList.add("等级");
        headerList.add("升级方式");
        headerList.add("服务商等级");
        headerList.add("国家");
        headerList.add("省份");
        headerList.add("城市");
        headerList.add("上级姓名");
        headerList.add("所属黑卡");
        headerList.add("所属1星");
        headerList.add("所属2星");
        headerList.add("所属3星");
        headerList.add("所属4星");
        headerList.add("所属EC");
        headerList.add("所属Sec");
        headerList.add("所属俱乐部");
        headerList.add("大区域黑钻PLUS数");
        headerList.add("大区域黑钻数");
        headerList.add("大区域白金数");
        headerList.add("大区域粉卡数");
        headerList.add("大区域注册会员数");
        headerList.add("直属客户黑钻PLUS数");
        headerList.add("直属客户黑钻数");
        headerList.add("直属客户白金数");
        headerList.add("直属客户粉卡数");
        headerList.add("直属客户注册会员数");
        headerList.add("升级时间");
        return headerList;
    }
}
